# -*- coding: utf-8 -*-
import os
from openai import OpenAI
from dotenv import load_dotenv

# 加载 .env 文件
load_dotenv()

class AIUtils:
    def process_query(self, query: str) -> str:
        """
        处理用户查询，调用 OpenAI 模型处理用户查询
        
        Args:
            query: 用户输入的查询字符串

        Returns:
            模型返回的处理结果字符串
        """
        api_key = os.getenv("API_KEY")  # 读取 OpenAI API Key
        base_url = os.getenv("BASE_URL")  # 读取 BASE URL
        model = os.getenv("MODEL")  # 读取 model

        client = OpenAI(api_key=api_key, base_url=base_url)

        # 调用大模型处理用户查询
        messages = [{"role": "user", "content": query}]

        # 请求 OpenAI 模型处理
        response = client.chat.completions.create(
            model=model,
            messages=messages
        )

        # 处理返回的内容
        content = response.choices[0]

        return content.message.content

